#include "linefield.h"
#include <QtPlugin>
#include <QLabel>
#include <QLineEdit>
#include <QRegExpValidator>

LineField::LineField()
{
}

QWidget *LineField::createDelegate(const QVariantMap &properties)
{
    QLineEdit *edit = new QLineEdit();

    if (properties.contains("regexp")) {
        QRegExpValidator *rev = new QRegExpValidator(QRegExp(properties["regexp"].toString()), this);
        edit->setValidator(rev);
    }

    return edit;
}

void LineField::setEditable(QWidget *delegate, bool editable)
{
    QLineEdit *edit = (QLineEdit *)delegate;
    edit->setReadOnly(!editable);
}

QVariant LineField::data(QWidget *delegate) const
{
    QLineEdit *edit = (QLineEdit *)delegate;
    return edit->text();
}

void LineField::setData(QWidget *delegate, const QVariant &data)
{
    QLineEdit *edit = (QLineEdit *)delegate;
    edit->setText(data.toString());
}

void LineField::clear(QWidget *delegate)
{
    QLineEdit *edit = (QLineEdit *)delegate;
    edit->clear();
}

Q_EXPORT_PLUGIN2(line-field, LineField)
